#include "widget.h"
#include "ui_widget.h"
#include <QMenu>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btnClearItems_clicked()
{
    ui->comboBox->clear();
    ui->plainTextEdit->clear();
}


void Widget::on_btnIniItems_clicked()
{
    // QStringList list;
    // list << "北京" << "上海" << "广州" << "深圳" << "西安";
    // for(const auto& e : list)
    // {
    //     ui->comboBox->addItem(e, Qt::UserRole);
    // }
    // ui->comboBox->addItems(list);
    ui->comboBox->clear();
    QIcon icon;
    icon.addFile("..\\..\\icons\\UNIT.ico");
    for(int i = 0; i< 20 ; ++i)
    {
        ui->comboBox->addItem(icon, QString("item%1").arg(i));
    }

    ui->plainTextEdit->clear();
}

void Widget::on_chkBoxEditable_clicked(bool checked)
{
    ui->comboBox->setEditable(checked);
}


void Widget::on_comboBox_currentIndexChanged(int index)
{
    ui->plainTextEdit->appendPlainText(QString("curretn index %1, current content %2")
                                           .arg(index).arg(ui->comboBox->currentText()));
}


void Widget::on_btnIni2_clicked()
{
    QMap<QString, int> City_Zone;
    City_Zone.insert("北京",10);
    City_Zone.insert("上海",21);
    City_Zone.insert("天津",22);
    City_Zone.insert("大连",411);
    City_Zone.insert("锦州",416);
    City_Zone.insert("徐州",516);
    City_Zone.insert("福州",591);
    City_Zone.insert("青岛",532);

    ui->comboBox2->clear();
    foreach(const QString  &str, City_Zone.keys())
    {
        ui->comboBox2->addItem(str, City_Zone[str]);
    }
}

void Widget::on_comboBox2_currentIndexChanged(int index)
{
        ui->plainTextEdit->appendPlainText(QString("curretn index %1, current content %2, current data: %3")
                                           .arg(index).arg(ui->comboBox2->currentText()).arg(ui->comboBox2->currentData().toInt()));
}

void Widget::on_btnClearText_clicked()
{
    ui->plainTextEdit->clear();
}

void Widget::on_comboBox2_currentTextChanged(const QString &arg1)
{
    ui->plainTextEdit->appendPlainText(arg1);
}

void Widget::on_comboBox_currentTextChanged(const QString &arg1)
{
    ui->plainTextEdit->appendPlainText(arg1);
}


void Widget::on_plainTextEdit_customContextMenuRequested(const QPoint &pos)
{
    QMenu* menu = ui->plainTextEdit->createStandardContextMenu();
    menu->exec(pos);
}

